
const cacheList = [];

const request = function(data){
	fetch('http://127.0.0.1:7001/monitor/web/report',{
		method: 'POST', // or 'PUT'
		body: JSON.stringify(data), // data can be `string` or {object}!
		headers: new Headers({
			'Content-Type': 'application/json'
		})
	})
	.then(function(response) {
		return response.json();
	})
	.then(function(res) {
		if(res.code == 0){
			cacheList = [];
		}
	});
}

let timer = null;
export const report = function(data){
	// 存入缓存
	cacheList.push(data)
	if(timer) return;
	timer = setTimeout(()=>{
		timer = null;
		request(cacheList)
	},5000)
}